<template>
  <div ref="vChart" class="v-chart"></div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  props: {
    option: {
      type: Object,
      default: () => []
    }
  },

  mounted () {
    this.SetChartOption(this.option)
  },

  beforeDestroy () {
    this.vChart.clear()
    this.vChart.dispose()
  },

  computed: {
    vChart () {
      const { vChart } = this.$refs
      return echarts.init(vChart)
    }
  },

  methods: {
    SetChartOption (option) {
      this.vChart.clear()
      this.vChart.setOption(option)
    }
  }
}
</script>

<style>
.v-chart {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 0;
}
</style>
